{{define "/chapter1/ajax.html"}}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/static/js/jquery.min.js"></script> 
</head>

<body>
    <form>
        姓名: <input type="text" id="name"><br>
        密码: <input type="password" id="passwd"><br>
        <input type="button" value="提交" id="add_btn"><br>
    </form>

    <script>
        var btn = document.getElementById("add_btn")
        btn.onclick = function() {
            var usrname = document.getElementById("name").value;
            var passwd = document.getElementById("passwd").value;
            // alert(usrname);
            // alert(passwd);
            $.ajax({
                url: "/chapter1/postajax",
                type:"POST",
                data:{
                    "name": usrname,
                    "passwd": passwd
                },
                
                success: function(data) {
                    alert(data["msg"]);
                    alert(data["code"]) 
                },

                fail: function(data){
                    
                },
            }) 
        }
    </script>
</body>

</html>
{{end}}